<template>
    <div class="xl-table">
        <xlUntil text="菜单设置" @addForm="addForm" :untilVisible="false" :queryParam="queryParam" @searchKeyWord="searchKeyWord" @delBatch="delBatch" :export-btn="false" :import-btn="false" :search-btn="false" :export-xls-data="columns" :export-xls-url="url.exportXlsUrl"></xlUntil>
        <div class="xl-table-content">
            <xlTable
                    :columns="columns"
                    :dataSource="data"
                    rowKey="id"
                    :pagination="pagination"
                    :loading="loading"
                    @change="handleTableChange"
                    bordered
                    :childrenColumnName="'childrenSystemMenuList'"
                    :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}">
                >
                <template v-slot:action="scope">
                    <a @click="editForm(scope.record)">编辑</a>
                    <a-divider type="vertical"/>
                    <a-dropdown>
                        <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
                        <a-menu slot="overlay">
                            <a-menu-item @click="seeForm(scope.record)">
                                <a>查看</a>
                            </a-menu-item>
                            <a-menu-item v-if="scope.record.systemMenuLevel != 3" @click="addChildren(scope.record)">
                                <a>添加子菜单</a>
                            </a-menu-item>
                            <a-menu-item>
                                <a-popconfirm title="确定删除吗?" @confirm="() => delForm(scope.record.id)">
                                    <a>删除</a>
                                </a-popconfirm>
                            </a-menu-item>
                        </a-menu>
                    </a-dropdown>
                </template>
            </xlTable>
        </div>
        <xlForm ref="xlForm" @handleOk="handleOk"></xlForm>
        <seeForm ref="seeForm"></seeForm>
    </div>
</template>

<script>

    import xlMixin from '@/components/mixin'
    import xlForm from './model/form'
    export default {
        name: "index",
        mixins:[xlMixin],
        data(){
            return{
                columns:[
                    {
                        title: '序号排序',
                        key: 'rowIndex',
                        align: "center",
                        fixed: 'left',
                        width:'180px',
                        sorter: (a) => a.id,//排序
                        customRender: function (t, r, index) {
                            return parseInt(index) + 1;
                        }
                    },
                    {
                        title: '菜单名称',
                        align: "center",
                        dataIndex: 'systemMenuName'
                    },
                    {
                        title: '路由路径',
                        align: "center",
                        dataIndex: 'routeUrl',
                    },
                    {
                        title: '排序',
                        align: "center",
                        dataIndex: 'dataSort',
                    },
                    {
                        title: 'icon',
                        align: "center",
                        dataIndex: 'systemMenuIcon',
                    },
                    {
                        title: '操作',
                        dataIndex: 'action',
                        align: "center",
                        fixed: 'right',
                        width:'150px',
                        scopedSlots: {customRender: 'action'},
                    }
                ],
                url: {
                    list: "/system/api/system/menu/page/_list",
                    add: '/system/api/system/menu/_save',
                    edit: '/system/api/system/menu/_save',
                    delete: "/system/api/system/menu/_remove",
                    deleteBatch: "/system/api/system/menu/_remove",
                    exportXlsUrl: "/ndo/api/new/dev/org/export/team/members",
                    importExcelUrl: "/person/project/upload/cjjn"
                }
            }
        },
        components:{
            xlForm
        },
        created(){
            this.formatMerge()
            this.pageOnload()
        },
        methods:{
            addChildren(data){
                this.$refs.xlForm.tableTitle = '新增'
                this.$refs.xlForm.formatData(this.columns)
                this.$refs.xlForm.visible = true
                this.$refs.xlForm.confirmLoading = false
                this.$refs.xlForm.formatForm({
                    systemMenuLevel:(Number(data.systemMenuLevel)+1).toString(),
                    parentSystemMenuId:data.id,
                    systemMenuIcon:'',
                    routeUrl:'',
                    systemMenuName:'',
                    dataSort:1
                })
                this.$refs.xlForm.type = 1
            },
            addForm() {
                this.$refs.xlForm.tableTitle = '新增'
                this.$refs.xlForm.formatData(this.columns)
                this.$refs.xlForm.visible = true
                this.$refs.xlForm.confirmLoading = false
                this.$refs.xlForm.formatForm({
                    systemMenuIcon:'',
                    routeUrl:'',
                    systemMenuName:'',
                    parentSystemMenuId:'0',
                    systemMenuLevel:'1',
                    dataSort:1
                })
                this.$refs.xlForm.type = 1
            },
        }
    }
</script>

<style scoped lang="less">
    .xl-table{
        .xl-table-content{
            padding: 16px;
        }
    }
</style>
